﻿using System;
using UnityEngine;

namespace KuiHuaBaoDian {

    public interface IMonoBehaviour {
    }

    public abstract class KHBD_MonoBehaviour : MonoBehaviour, IMonoBehaviour, IEntity {

        protected KHBD_MonoBehaviour() : base() { }

        public event IObject.DisposingDelegate Disposing;

        public bool IsDisposed { get; private set; }

        public bool IsDisposing { get; private set; }

        protected virtual void Awake() {
            AutowireUtility.Autowire(this);
        }

        protected void OnDestroy() {
            if (!IsDisposed) {
                if (Disposing != null) {
                    Disposing.Invoke();
                    Disposing = null;
                }
                IsDisposing = true;
                Dispose();
                IsDisposed = true;
                IsDisposing = false;
                AutowireUtility.Dispose(this);
            }
        }

        protected virtual void Dispose() {
        }
    }
}
